﻿#include <stdio.h>
#include "BridgeCpp.h"
#include "Finder/NavHelper.h"
#include "Finder/PathFinder.h"

dtNavMesh* GetNavMesh(char* name)
{

	dtNavMesh* result = NavHelper::GetNavMesh(name);
	delete[]name;
	return result;
}

PathFinder* GetFinder(dtNavMesh* navmesh)
{
	return NavHelper::GetFinder(navmesh);
}

void ReleaseMap()
{
	
	NavHelper::ReleaseMap();
}

float* FindPath(PathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count)
{
	return NavHelper::FindPath(finder, sposX, sposY, sposZ, eposX, eposY, eposZ,count);
}

float* CalcNear(PathFinder* finder, float sposX, float sposY, float sposZ, int* count)
{
	return NavHelper::CalcNear(finder, sposX, sposY, sposZ, count);
}

float* CalcRaycast(PathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count)
{
	return NavHelper::CalcRaycast(finder, sposX, sposY, sposZ, eposX, eposY, eposZ, count);
}

// 释放地图
void FreeNavMesh(PathFinder* pathfinder)
{
	delete pathfinder;
}

// Temp obstacles的接口
TempObstaclesNavMesh* GetNavMeshTO(char* name)
{
	TempObstaclesNavMesh* result =  NavHelper::GetNavMeshTO(name);
	delete[] name;
	return result;
}

void ReleaseMapTO()
{
	NavHelper::ReleaseMapTO();
}

float* FindPathTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count)
{
	return NavHelper::FindPathTO(toNavMesh, sposX, sposY, sposZ, eposX, eposY, eposZ, count);
}

BOOL FindPathExTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ)
{
	return NavHelper::FindPathExTO(toNavMesh, sposX, sposY, sposZ, eposX, eposY, eposZ) ? TRUE : FALSE;
}

float* GetPath(TempObstaclesNavMesh* toNavMesh, int* count)
{
	return NavHelper::GetPathTO(toNavMesh, count);
}

float* CalcNearTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, int* count)
{
	return NavHelper::CalcNearTO(toNavMesh, sposX, sposY, sposZ, count);
}

float* CalcRaycastTO(TempObstaclesNavMesh* toNavMesh, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count)
{
	return NavHelper::CalcRaycastTO(toNavMesh, sposX, sposY, sposZ,eposX,eposY,eposZ, count);
}

// 增加圆柱体阻挡
void AddCylinderTO(TempObstaclesNavMesh* toNavMesh, char* tag, float posX, float posY, float posZ, float radius, float height)
{
	NavHelper::AddCylinderTO(toNavMesh, tag, posX, posY, posZ, radius, height);
	delete[] tag;
}

void AddObbBox(TempObstaclesNavMesh* toNavMesh, char* tag, float centX, float centY, float centZ, float halfX, float halfY, float halfZ, float rotaY)
{
	NavHelper::AddObbBox(toNavMesh, tag, centX, centY, centZ, halfX, halfY, halfZ, rotaY);
	delete[] tag;
}

void AddAabbBox(TempObstaclesNavMesh* toNavMesh, char* tag, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
{
	NavHelper::AddAabbBox(toNavMesh, tag, minX, minY, minZ, maxX, maxY, maxZ);
	delete[] tag;
}

void RemoveTOByTag(TempObstaclesNavMesh* toNavMesh, char* tag)
{
	NavHelper::RemoveTOByTag(toNavMesh, tag);
	delete[] tag;
}

void RemoveAllTO(TempObstaclesNavMesh* toNavMesh)
{
	NavHelper::RemoveAllTO(toNavMesh);
}

void Update(TempObstaclesNavMesh* toNavMesh)
{
	NavHelper::Update(toNavMesh);
}

void FreeToNavMesh(TempObstaclesNavMesh* toNavMesh)
{
	NavHelper::FreeToNavMesh(toNavMesh);
}



#pragma region 新的动态Mesh

/*
不想使用C++管理Mesh与Finder
带Key表示放到了Map里
创建一个新的Finder
*/
ObsNavMesh* NewObsNavMesh(char* filepath, char* key) {
	auto result = NavHelper::NewObsNavMesh(filepath, key);
	delete[] filepath;
	delete[] key;
	return result;
}
/*
不想使用C++管理Mesh与Finder
创建一个新的Finder
*/
ObsPathFinder* NewObsPathFinder(ObsNavMesh* mesh) {
	auto result = NavHelper::NewObsPathFinder(mesh);
	return result;
}
//获取Mesh
// filepath 文件路径必须有
// key 缓存起来的key，必须有
ObsNavMesh* GetObsNavMesh(char* filepath, char* key) {
	auto result = NavHelper::GetObsNavMesh(filepath, key);
	delete[] filepath;
	delete[] key;
	return result;
}
//获取Mesh对应的寻路对象
//  filepath 文件路径
// key 缓存起来的key
// filepath 和key只能有一个，没有key就读一个新的Mesh，然后就通过Key要一个旧的
ObsPathFinder* GetPathFinder(char* filepath, char* key) {
	auto result = NavHelper::GetPathFinder(filepath, key);
	delete[] filepath;
	delete[] key;
	return result;
}
// 释放寻路对象
void FreeObsPath(ObsPathFinder* finder) {
	NavHelper::FreeObsPath(finder);
}
// 从寻路对应里获取Mesh的引用
ObsNavMesh* GetObsNavMeshByFinder(ObsPathFinder* finder) {
	return NavHelper::GetObsNavMeshByFinder(finder);
}

#pragma region 动态阻挡有关
// 增加圆柱体阻挡
void ObsAddCylinder(ObsNavMesh* toNavMesh, char* tag, float posX, float posY, float posZ, float radius, float height) {
	NavHelper::ObsAddCylinder(toNavMesh, tag, posX, posY, posZ, radius, height);
	delete[] tag;
}
// 增加OBB
void ObsAddObbBox(ObsNavMesh* toNavMesh, char* tag, float centX, float centY, float centZ, float halfX, float halfY, float halfZ, float rotaY) {
	NavHelper::ObsAddObbBox(toNavMesh, tag, centX, centY, centZ, halfX, halfY, halfZ, rotaY);
	delete[] tag;
}
// 增加AABB
void ObsAddAabbBox(ObsNavMesh* toNavMesh, char* tag, float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
	NavHelper::ObsAddAabbBox(toNavMesh, tag, minX, minY, minZ, maxX, maxY, maxZ);
	delete[] tag;
}
// 按照名字删除掉一系列动态阻挡
void ObsRemoveTOByTag(ObsNavMesh* toNavMesh, char* tag) {
	NavHelper::ObsRemoveTOByTag(toNavMesh, tag);
	delete[] tag;
}
// 移除地图中全部的动态阻挡
void ObsRemoveAllTO(ObsNavMesh* toNavMesh) {
	NavHelper::ObsRemoveAllTO(toNavMesh);
}

// 如果有动态阻挡cache，将cache生效到动态阻挡中去
void ObsUpdate(ObsNavMesh* toNavMesh) {
	NavHelper::ObsUpdate(toNavMesh);
}
#pragma endregion

#pragma region 寻路有关
// 进行一次寻路，返回路点列表
float* ObsFindPath(ObsPathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count) {
	return NavHelper::ObsFindPath(finder, sposX, sposY, sposZ, eposX, eposY, eposZ, count);
}

// 查询某个点在mesh里面附近的点
float* ObsCalcNear(ObsPathFinder* finder, float sposX, float sposY, float sposZ, int* count) {
	return NavHelper::ObsCalcNear(finder, sposX, sposY, sposZ, count);
}

// 射线检测一次，如果之间遇到障碍无法穿过，将会把点返回回去
float* ObsCalcRaycast(ObsPathFinder* finder, float sposX, float sposY, float sposZ, float eposX, float eposY, float eposZ, int* count) {
	return NavHelper::ObsCalcRaycast(finder, sposX, sposY, sposZ, eposX, eposY, eposZ, count);
}
#pragma endregion
#pragma endregion